#include <bits/stdc++.h>
using namespace std;
int main() {	
    long long n, x;
    cin >> n >> x;
    long long ans = 0, base = 1;
    for(int i = 1; i <= 19; i++){
	    if (base > n) break;
        long long high = n / base / 10, cur = (n / base) % 10, low = n % base;
        ans += high * base;
        if (x == 0) {
            if (cur == x)
                ans += low + 1 - base;
        } else {
            if (cur > x)
                ans += base;
            if(cur == x)
            	ans += low + 1;
    	}	
    	base *= 10;
	}
	cout << ans << endl;
	return 0;
}